import zmq
import time

def publisher():
    context = zmq.Context()
    socket = context.socket(zmq.PUB)
    socket.bind("tcp://*:5556")

    try:
        counter = 0
        while True:
            message = f"Message {counter}"
            socket.send_string(message)
            print(f"Published: {message}")
            counter += 1
            time.sleep(1)
    except KeyboardInterrupt:
        print("Publisher stopped.")
    finally:
        socket.close()
        context.term()

if __name__ == "__main__":
    publisher()
